package net.kts.attraction.subway.positon;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class SubwayTransferStationDaoSQLite extends SQLiteOpenHelper {

	public SubwayTransferStationDaoSQLite(Context context, String name,
			CursorFactory factory, int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub

	}
	
	
	public List<Integer> selectTransferStation(int stationCode) {
		
		List<Integer> lineList = null;
		String lineNumStationCode= null;
		String[] lineNumStationCodes = null;
		
		String sql = "";
		
		sql += " select * from TBL_TRANSFER_STATION ";
		sql += " where ";
		sql += " station_code = " + stationCode;
		
		Cursor cursor = getReadableDatabase().rawQuery(sql, null);
		
		cursor.moveToFirst();
		
		
		while(!cursor.isAfterLast()) {
			
			lineNumStationCode  = cursor.getString(1);
			
			lineNumStationCodes = lineNumStationCode.split(";");
			
			for(int indexI = 0; indexI < lineNumStationCodes.length; indexI += 2) {
				if(lineList == null) {
					lineList = new ArrayList<Integer>();
				}
				
				lineList.add(Integer.valueOf(lineNumStationCodes[indexI].trim()));
			}
			
			cursor.moveToNext();
		}
		
		
		return lineList;
	}

}
